using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using DAL;
using Utility;

namespace BUS
{
    public class tbSanPhamBUS
    {
        public static int Insert(tbSanPham sanpham)
        {
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
           return spDAL.Insert(sanpham);
        }
        public static void Update(tbSanPham sanpham)
        {
            tbSanPhamDAL spDAl = new tbSanPhamDAL();
            spDAl.Update(sanpham);
        }
        //public static void UpdateTT(tbSanPham sanpham)
        //{
        //    tbSanPhamDAL spDAL = new tbSanPhamDAL();
        //    spDAL.UpdateTT(sanpham);
        //}
        public static void Delete(int iD)
        {
            tbSanPhamDAL spDAl = new tbSanPhamDAL();
            spDAl.Delete(iD);
        }
        public static tbSanPhamCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
            return spDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbSanPhamCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
            return spDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbSanPham GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbSanPhamColumns.MaSP.ToString(), Condition.EQUAL, iD);
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
            tbSanPhamCollection spCollection = spDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
            if (spCollection.Count > 0)
                return spCollection[0];
            return null;
        }
        public static tbSanPhamCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
            return spDAL.Get(cri.Criter, 1, number, tbSanPhamColumns.MaSP.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbSanPhamCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbSanPhamDAL spDAL = new tbSanPhamDAL();
            return spDAL.Get(cri.Criter, 1, number, tbSanPhamColumns.MaSP.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}





//    public class tbSanPhamBUS
//    {
//        public static int Insert(tbSanPham sanpham)
//        {
//            tbSanPhamDAL spDAL = new tbSanPhamDAL();
//           return spDAL.Insert(sanpham);
//        }
//        public static void Update(tbSanPham sanpham)
//        {
//            tbSanPhamDAL spDAl = new tbSanPhamDAL();
//            spDAl.Update(sanpham);
//        }
//        //public static void UpdateTT(tbSanPham sanpham)
//        //{
//        //    tbSanPhamDAL spDAL = new tbSanPhamDAL();
//        //    spDAL.UpdateTT(sanpham);
//        //}
//        public static void Delete(int iD)
//        {
//            tbSanPhamDAL spDAl = new tbSanPhamDAL();
//            spDAl.Delete(iD);
//        }
//        public static tbSanPhamCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
//        {
//            tbSanPhamDAL spDAL = new tbSanPhamDAL();
//            return spDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
//        }
//        //public static tbSanPhamCollection GetAll()
//        //{
//        //    int total = 0;
//        //    Criteria cri = new Criteria();
//        //    tbSanPhamDAL spDAL = new tbSanPhamDAL();
//        //    return spDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
//        //}
////        public static tbSanPham GetByID(int iD)
////        {
////            int total = 0;
////            Criteria cri = new Criteria();
////            cri.add(Condition.AND, tbSanPhamColumns.MaSP.ToString(), Condition.EQUAL, iD);
////            tbSanPhamDAL spDAL = new tbSanPhamDAL();
////            tbSanPhamCollection spCollection = spDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
////            if (spCollection.Count > 0)
////                return spCollection[0];
////            return null;
////        }
//        public static tbSanPhamCollection GetAll()
//        {
//            int total = 0;
//            tbSanPhamDAL spDAL = new tbSanPhamDAL();
//            return spDAL.Get("where 1=1", 0, 0, tbSanPhamColumns.MaSP.ToString(), "ASC", out total);
//        }

//        public static tbSanPham GetByID(int iD)
//        {
//            int total = 0;
//            tbSanPhamDAL spDAL = new tbSanPhamDAL();
//           tbSanPhamCollection spCollection = spDAL.Get("where " + tbSanPhamColumns.MaSP.ToString() + "=" + iD.ToString(), 0, 0, tbSanPhamColumns.MaSP.ToString(), "ASC", out total);
//           if (spCollection.Count > 0)
//                return spCollection[0];
//            return null;
//        }
////        //public static tbSanPhamCollection GetLimited(int number)
////        //{
////        //    int total = 0;
////        //    Criteria cri = new Criteria();
////        //    tbSanPhamDAL spDAL = new tbSanPhamDAL();
////        //    return spDAL.Get(cri.Criter, 1, number, tbSanPhamColumns.MaSP.ToString(), OrderDirection.DESC.ToString(), out total);
////        //}
////        //public static tbSanPhamCollection GetPromotion(int number)
////        //{
////        //    int total = 0;
////        //    Criteria cri = new Criteria();
////        //    tbSanPhamDAL spDAL = new tbSanPhamDAL();
////        //    return spDAL.Get(cri.Criter, 1, number, tbSanPhamColumns.MaSP.ToString(), OrderDirection.DESC.ToString(), out total);
////        //}
//    }
//}
